package com.tensquare.article.controller;

import com.tensquare.article.service.ArticleService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 1.文章审核
     * @param articleId 要审核的文章id
     * @return  是否成功的状态信息
     */
    @PutMapping("examine/{articleId}")
    public Result examine(@PathVariable String articleId){
        try {
            articleService.examine(articleId);
            return new Result(StatusCode.OK,true,"文章审核成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(StatusCode.ERROR,false,"文章审核失败！");
        }
    }

    /**
     * 2.文章点赞
     * @param articleId 点赞的文章id
     * @return  是否成功点赞的状态信息
     */
    @PutMapping("thumbup/{articleId}")
    public Result thumbup(@PathVariable String articleId){
        try {
            articleService.thumbup(articleId);
            return new Result(StatusCode.OK,true,"文章点赞成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(StatusCode.ERROR,false,"文章点赞失败！");
        }
    }
}
